﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.huigo.Framework.ServiceUtils;

namespace com.huigo.B2B.Web.center.account
{
    public partial class Consumption : BasePage
    {
        private DateTime startTime
        {
            get
            {
                return com.loto.Common.Utils.IsDate(Request.Form["beginDate"]) ? Convert.ToDateTime(Request.Form["beginDate"]) : DateTime.MinValue;
            }
        }
        private DateTime endTime
        {
            get
            {
                return com.loto.Common.Utils.IsDate(Request.Form["endDate"]) ? Convert.ToDateTime(Request.Form["endDate"]) : DateTime.MinValue;
            }
        }
        private int type
        {
            get
            {
                return string.IsNullOrEmpty(Request.Form["type"]) ? int.MinValue : Convert.ToUInt16(com.loto.Common.Utils.SqlEscape(Request.Form["type"]));
            }
        }
        private int pageIndex
        {
            get
            {
                return com.loto.Common.TypeParse.StrToInt(Request.QueryString["page"], 1);
            }
        }
        public string dateStart = string.Empty;
        public string dateEnd = string.Empty;
        public string Notiy = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {            
            BindData();
        }
        private void BindData()
        {
            if (startTime != DateTime.MinValue)
            {
                dateStart = Convert.ToDateTime(startTime).ToString("yyyy-MM-dd");
            }
            if (endTime != DateTime.MinValue)
            {
                dateEnd = Convert.ToDateTime(endTime).ToString("yyyy-MM-dd");
            }
            List<RequestFuncParams> list = new List<RequestFuncParams>();
            list.Add(new RequestFuncParams("custFid", CustId.ToString()));
            list.Add(new RequestFuncParams("startTime", startTime.ToString()));
            list.Add(new RequestFuncParams("endTime", endTime.ToString()));
            list.Add(new RequestFuncParams("type", type.ToString()));
            list.Add(new RequestFuncParams("PageSize", pageInfo.PageSize.ToString()));
            list.Add(new RequestFuncParams("PageIndex", pageIndex.ToString()));
            BaseService service = new BaseService();
            ParserXml parser = service.RequestEntryService(Dict.ERequestFunc.GET_CUST_FEE_FLOW, list);
            if (parser != null && parser.RowsCount > 0)
            {
                pageInfo.RecordCount = Convert.ToInt16(parser["RecordCount", 0]);
                pageInfo.CurrentPageIndex = pageIndex;
                pageInfo.PageURLFormat = GetPagerUrl();
                CustFeeFlowContent.DataSource = parser.ModelList;
                CustFeeFlowContent.DataBind();
            }
            else
            {
                CustFeeFlowContent.DataSource = null;
                CustFeeFlowContent.DataBind();
                Notiy = "<table class=\"table table-bordered table-striped responsive-utilities table-hover\"><thead><tr><th>日期</th><th>消费明细</th><th>变动金额</th></tr></thead><tbody><tr><td colspan=\"3\" style=\"text-align:center;\">没有相关信息</td></tr></tbody></table>";
            }
        }
        private string GetPagerUrl()
        {
            string url = "Consumption.aspx?";
            url += "page={0}";
            if (startTime != DateTime.MinValue)
                url += "&beginDate=" + startTime;
            if (endTime != DateTime.MinValue)
                url += "&endDate=" + endTime;
            if (type != int.MinValue)
                url += "&type=" + type;
            return url;
        }
        protected void pageInfo_PageChanged(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        public string selected(string flowType)
        {
            if (Convert.ToInt32(flowType) == type)
            {
                return "selected=\"selected\"";
            }
            else
            {
                return string.Empty;
            }
        }
        public string GetUserFee()
        {
            List<RequestFuncParams> list = new List<RequestFuncParams>();
            list.Add(new RequestFuncParams("custId", CustId.ToString()));
            BaseService service = new BaseService();
            ParserXml parser = service.RequestEntryService(Dict.ERequestFunc.GET_CUST_USEFUL_FEE, list);
            if (parser != null && parser.RowsCount > 0)
            {
                return Convert.ToDecimal(parser["CustUsefulFee", 0]).ToString("0.00");
            }
            else
            {
                return "0";
            }
        }
    }
}
